<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<link rel="stylesheet" media="screen" href="css/docs.css"/>
<link rel="stylesheet" media="screen" href="lib/jqplot/jquery.jqplot.min.css"/>
<!-- jQplot SETUP -->
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/jqplot/excanvas.js"></script>
<![endif]-->
<script type="text/javascript" src="lib/jqplot/jquery.jqplot.min.js"></script>
<script type="text/javascript" src="lib/jqplot/plugins/jqplot.categoryAxisRenderer.min.js"></script>
<script type="text/javascript" src="lib/jqplot/plugins/jqplot.barRenderer.min.js"></script>
<script type="text/javascript" src="lib/jqplot/plugins/jqplot.highlighter.min.js"></script>
<script type="text/javascript" src="lib/jqplot/plugins/jqplot.dateAxisRenderer.min.js"></script>
<script type="text/javascript" src="lib/jqplot/plugins/jqplot.pointLabels.min.js"></script>
<script type="text/javascript" src="lib/jqplot/plugins/jqplot.pieRenderer.min.js"></script>
<script type="text/javascript" src="lib/jqplot/plugins/jqplot.donutRenderer.min.js"></script>
<script type="text/javascript" src="lib/jqplot/plugins/jqplot.bubbleRenderer.min.js"></script>
<link rel="stylesheet" media="screen" href="lib/datatables/css/vpad.css"/>
<script type="text/javascript" src="lib/datatables/js/jquery.dataTables.js"></script>


<!-- jQplot SETUP END -->

<h1 class="page-title">数据输入</h1>
<%@include file="/WEB-INF/pages/exam/exam_quan_input_add.jsp"%>

<div class="container_12 clearfix leading">

    <div class="tabs side grid_6" id="history_div">
        <h5>历史审核</h5>
        <ul class="clearfix">
            <s:if test="#request.examQuanScoreAuditings != null and #request.examQuanScoreAuditings.size() > 1">
                <s:iterator value="#request.examQuanScoreAuditings" status="sta">
                    <li><a class="current" href="#">历史审核#<s:property value="#request.sta.index+1"/></a></li>
                </s:iterator>
            </s:if>
            <s:else>
                <li><a class="current" href="#">没有历史记录</a></li>
            </s:else>
        </ul>
        <section>
            <s:if test="#request.examQuanScoreAuditings != null and #request.examQuanScoreAuditings.size() > 1">
                <s:iterator value="#request.examQuanScoreAuditings" var="ad" status="sta">
                    <section style="display: block;" class="clearfix">
                        <%--<h4>2012年3月22日</h4>--%>
                        <div class="grid_12 alpha">
                            <h4>
                            <s:if test="#request.ad.create_date != null">
                              <s:date name="#request.ad.create_date" format="yyyy-MM-dd" />
                            </s:if>
                            </h4>
                            <hr>
                            <ol class="nostyle">
                                <li>
                                    <%--TODO:读审核者(审核时登录用户)--%>
                                    <p class="title"> 审核者${ad.id}
                                        <button type="reset" class="button" style="float: right">
                                            <span style="background:url(${ctx}/images/img/accept.png)" class="icon">&nbsp;</span>${ad.status.name}
                                        </button>
                                    </p>
                                    <p>${ad.auditContent}</p>
                                </li>
                            </ol>
                        </div>
                    </section>
                </s:iterator>
            </s:if>
            <s:else>
                <section style="display: none;" class="clearfix">
                    <div class="grid_12 alpha">没有历史审核记录</div>
                </section>
            </s:else>
        </section>
    </div>


    <div class="side grid_6">
        <h5>当前审核</h5>
        <div class="accordion">
            <s:if test="#request.status!=null and #request.status.toString() == 'within_audit'">
            <header class="current">
                <h2>${current_user}${com_sihai_ehr_session_user_name} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <input type="radio" name="r1" id="r_pass"> 同意
                    <input type="radio" name="r1" id="r_reject"> 不同意
                    <button class="button" type="button" onclick="doAudit()"><span class="icon" style="background:url(${ctx}/images/img/help.png)">&nbsp;</span>确定审核</button>
                </h2>
            </header>
            <section class="clearfix" style="display: block;">
                <h6>审核意见</h6> <hr>
                <textarea rows="5" style="width:100%" id="auditContent"></textarea>
            </section>
            </s:if>
            <s:else>
                已审核
            </s:else>
        </div>
    </div>

    <div class="grid_12">
        <br/>
        <div class="form-action clearfix">
            <p>
                <a href="#exam/quan_audit_main.xhtml?examPeriodStr=${examPeriodStr}&examPeriodEnum=${examPeriodEnum}" class="button"><span class="icon" style="background:url(${ctx}/images/img/arrow_undo.png)">&nbsp;</span>返回</a>
            </p>
        </div>
    </div>
</div>

<div class="clear"></div>

<script type="text/javascript" src="${ctx}/js/global_util.js"></script>
<script type="text/javascript">
    var historys = new Array();
    var current_detail_id = -1;
    $(function(){
        var temp = "${quanScoreDetailId}";
        if(temp.length > 0 && temp > 0){
            $("input[type='radio'][name='select_detail']").each(function() {
                if($(this).val() == temp){
                    $(this).attr("checked", true);
                    $(this).parent("span").attr("class", "checked")
                    return false; //退出each(相当于break, return true相当于continue)
                }
            });

            findAuditHistory(temp);
        }
    });

    function doAudit(){
        if(current_detail_id <= 0){
            return;
        }

        var status = null;
        if($("#r_pass").parent("span").attr("class") == "checked"){
            status = "pass_audit";
        }else if($("#r_reject").parent("span").attr("class") == "checked"){
            status = "reject_audit";
        }
        if(status == null){
            alert("请选择审核结果");
            return;
        }
        var auditContent = $("#auditContent").val();
        if(checkNull(auditContent)){
            alert("请输入审核意见")
            return;
        }

        var data ={"quanScoreDetailId":current_detail_id, "status":status, "auditContent":auditContent, "quanScore.id":"${quanScore.id}", "examPeriodStr":"${examPeriodStr}","examPeriodEnum":"${examPeriodEnum}"};
        var url="${ctx}/exam/quan_audit.xhtml";
        $.ajax(url, {
            type:"POST",
            data:data,
            dataType:"html",
            cache:false,
            success:function(a) {
                return pageDownloaded(a, url)
            },
            complete:function(b) {
            }
        });
    }
    function findAuditHistory(detailId){
        if(detailId > 0){
            if(detailId == current_detail_id){
                return;
            }
            current_detail_id = detailId;

            var url = "/exam/quan_audit_history.xhtml?quanScoreDetailId=" + detailId;
            $.ajax(url, {
                type:"POST",
                //data:data,
                dataType:"html",
                cache:false,
                success:function(a) {
                    //return pageDownloaded(a, url)
                    $("#history_div").html(a);
                },
                complete:function(b) {
                }
            });
        }
    }

    function changeTab(obj, i){
        $("a.current").removeClass("current");
        $(obj).addClass("current");

        $("section.wxn").hide();
        $("#section_"+i).show();
    }
</script>